package com.github.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.base.domain.RoleDept;
import com.github.base.mapper.RoleDeptMapper;
import com.github.base.service.RoleDeptService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Slf4j
@Component
@RequiredArgsConstructor
public class RoleDeptServiceImpl extends ServiceImpl<RoleDeptMapper, RoleDept> implements RoleDeptService {
    private final RoleDeptMapper roleDeptMapper;

    @Override
    public Set<Long> findDeptIdsByRoleIds(Collection<Long> roleIds) {
        LambdaQueryWrapper<RoleDept> query = Wrappers.lambdaQuery(RoleDept.class);
        query.in(RoleDept::getRoleId, roleIds);
        List<RoleDept> roleDeptList = roleDeptMapper.selectList(query);
        return roleDeptList.stream().map(RoleDept::getDeptId).collect(Collectors.toSet());
    }
}
